package com.jiuyue.movehouse.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jiuyue.movehouse.annotion.PageInfo;
import com.jiuyue.movehouse.entity.Car;
import com.jiuyue.movehouse.entity.CarType;
import com.jiuyue.movehouse.entity.ExtInfo;
import com.jiuyue.movehouse.entity.Order;
import com.jiuyue.movehouse.service.CarTypeService;
import com.jiuyue.movehouse.service.ExtInfoService;
import com.jiuyue.movehouse.service.OrderService;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author yourFather
 * @since 2022-02-11
 */
@RestController
@RequestMapping("/order")
@AllArgsConstructor
public class OrderController {

    private OrderService orderService;

    private ExtInfoService extInfoService;

    private CarTypeService carTypeService;

    @PostMapping("reservation")
    public Order reservation(@RequestBody @Validated(Order.Reservation.class) Order order) {
        return orderService.reservation(order);
    }

    @GetMapping("getMyOrder/{userId}")
    public List<Order> getMyOrder(@PathVariable Long userId) {
        return orderService.getMyOrder(userId);
    }

    @PostMapping("cancelOrder/{orderId}")
    public Order cancelOrder(@PathVariable Long orderId) {
        return orderService.cancelOrder(orderId);
    }

    @PostMapping("payOrder/{orderId}")
    public Order payOrder(@PathVariable Long orderId) {
       return orderService.payOrder(orderId);
    }

    @GetMapping("getExtInfoList")
    public List<ExtInfo> getExtInfoList() {
        return extInfoService.list();
    }

    @GetMapping("getCarTypeList")
    public List<CarType> getCarTypeList() {
        return carTypeService.list();
    }

    @GetMapping("getOrderList")
    public Page<Order> getOrderList(@PageInfo Page page, Order order) {
        return orderService.getOrderList(page,order);
    }

    @GetMapping("getCarList")
    public List<Car> getCarList() {
        return orderService.getCarList();
    }

    @PostMapping("receiveOrder/{orderId}/{carId}")
    public void receiveOrder(@PathVariable Long orderId,@PathVariable Long carId) {
         orderService.receiveOrder(orderId,carId);
    }

    @PostMapping("completeOrder/{orderId}/{realPrice}")
    public void completeOrder(@PathVariable Long orderId,@PathVariable BigDecimal realPrice) {
        orderService.completeOrder(orderId,realPrice);
    }
}

